package com.wlstock.funi.model;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.wlstock.funi.utils.CaculateUtils;
import com.wlstock.funi.utils.StockUtils;

import java.util.Date;


/**
 * 来源暂时一共有3种，当来自万隆跟问股过滤的，暂时不需要存放到本地
 * @author admin
 *
 */
@DatabaseTable 
public class SelfFundModel extends BaseModel{
	public final static int SOURCE_NONE = 0X00000;
	/**
	 * 来源万隆
	 */
	public final static int SOURCE_WANGLONG = 0X00001;
	/**
	 * 来源问股
	 */
	public final static int SOURCE_WENGU    = 0x00002;
	/**
	 * 来源指标
	 */
	public static final int SOURCE_ZB       = 0x00003;
	/**
	 * 来源自己手动增加
	 */
	public static final int SOURCE_CUSTOMADD = 0x00004;

	public static final String CODE_SH = "000001";

	public static final String CODE_SZ = "399001";

	public static final String CODE_CY = "399006";

	public static final String TAG_DEFAULT = "DEFAULT";

	@DatabaseField	//自选股来源
	private int sourceCode = SOURCE_NONE;
	@DatabaseField (id = true)	//证券代码
	private String stockNo;
	@DatabaseField	//证券名字
	private String stockName;
	@DatabaseField	//日线url
	private String stkDayK;
	@DatabaseField	//当前价格
	private float curPrice;
	@DatabaseField //今开
	private float curOpen;
	@DatabaseField	//最高价
	private float hPrice;
	@DatabaseField	//最低价
	private float lowPrice;
	@DatabaseField	//昨收
	private float lastClose;
	@DatabaseField	//加入时间
	private String createTime;
	@DatabaseField	//更新时间
	private String updateTime;
	@DatabaseField	//是否持仓
	private int  isInAccount;
	@DatabaseField
	private String tag;//标签，用于在自己添加的情况下增加一种额外分组
	
	//Wanglong 的字段
	@DatabaseField
	private float  tradePrice;//持仓成本
	@DatabaseField
	private Date   tradeTime;
	@DatabaseField
	private String allPty;
	@DatabaseField
	private String userAblePty;
	@DatabaseField
	private int    tradeType;//交易类型
	@DatabaseField
	private int fundid;
	@DatabaseField 
	private String fundName;
	@DatabaseField
	private String tradedDay;//"今天"、"昨天"
	@DatabaseField
	private float profitRate;//本期收益
	@DatabaseField
	private float range;//本期排名
	@DatabaseField
	private float nums;//本期排名
	
	public String isRecord = "Y";
	
	@DatabaseField
	private String myCostPrice; //我的持仓成本
	@DatabaseField
	private float myProfiteRate;//我的浮动盈亏
	@DatabaseField
	private int stkQty;//我的当前可用数量

	private String stkLineH5;

	@DatabaseField
	private String backupInfo;

	
	public SelfFundModel(){}
	/*来源于万隆的时候额外字段*/
	public SelfFundModel(OperateModel model){
		this.fundid     = model.getFundid();
		this.fundName   = model.getFundName();
		this.sourceCode = SOURCE_WANGLONG;
		this.stockNo    = model.getStockNo();
		this.stockName  = model.getStockName();
		this.tradePrice = model.getTradePrice();
		this.stkDayK    = StockUtils.getSinaDayKUrl(model.getStockNo());
		this.tradeTime  = model.getTradedDate();
		this.tradeType  = model.getTradeType();
		this.tradedDay  = model.getTradedDay();
		this.profitRate = model.getProfitRate();
		this.range      = model.range;
		this.nums       = model.nums;
		this.backupInfo = model.toString();
	}

	public SelfFundModel(StrategyFundModel model) {
		this.sourceCode = SOURCE_WENGU;
		this.stockNo = model.getStkNo();
		this.stockName = model.getStkName();
		this.tradeType = model.getTradeType();
		this.backupInfo = model.toString();
	}

	public SelfFundModel(MyAccountStocks acStock) {
		// TODO Auto-generated constructor stub
		setMyStock(acStock);
	}



	public int getSourceCode() {
		return sourceCode;
	}
	public void setSourceCode(int sourceCode) {
		this.sourceCode = sourceCode;
	}
	public String getStockNo() {
		return stockNo;
	}
	public void setStockNo(String stockNo) {
		this.stockNo = stockNo;
	}
	public String getStockName() {
		return stockName;
	}
	public void setStockName(String stockName) {
		this.stockName = stockName;
	}
	public String getStkDayK() {
		return StockUtils.getSinaDayKUrl(stockNo);
	}
	public void setStkDayK(String stkDayK) {
		this.stkDayK = stkDayK;
	}
	public int getIsInAccount() {
		return isInAccount;
	}
	public void setIsInAccount(int isInAccount) {
		this.isInAccount = isInAccount;
	}

	public float getCurPrice() {
		return curPrice;
	}
	public void setCurPrice(float curPrice) {
		this.curPrice = curPrice;
	}
	public float getCurOpen() {
		return curOpen;
	}
	public void setCurOpen(float curOpen) {
		this.curOpen = curOpen;
	}
	public float gethPrice() {
		return hPrice;
	}
	public void sethPrice(float hPrice) {
		this.hPrice = hPrice;
	}
	public float getLowPrice() {
		return lowPrice;
	}
	public void setLowPrice(float lowPrice) {
		this.lowPrice = lowPrice;
	}
	public float getlastClose() {
		return lastClose;
	}
	public void setlastClose(float lastClose) {
		this.lastClose = lastClose;
	}
	public Date getTradeTime() {
		return tradeTime;
	}
	public void setTradeTime(Date tradeTime) {
		this.tradeTime = tradeTime;
	}
	public float getTradePrice() {
		return tradePrice;
	}
	public void setTradePrice(float tradePrice) {
		this.tradePrice = tradePrice;
	}
	public int getTradeType() {
		return tradeType;
	}
	public void setTradeType(int tradeType) {
		this.tradeType = tradeType;
	}
	public String getTradedDay() {
		return tradedDay;
	}
	public void setTradedDay(String tradedDay) {
		this.tradedDay = tradedDay;
	}
	public float getProfitRate() {
		return profitRate;
	}
	public void setProfitRate(float profitRate) {
		this.profitRate = profitRate;
	}
	public float getRange() {
		return range;
	}
	public void setRange(float range) {
		this.range = range;
	}
	public float getNums() {
		return nums;
	}
	public void setNums(float nums) {
		this.nums = nums;
	}
	public int getFundid() {
		return fundid;
	}
	public void setFundid(int fundid) {
		this.fundid = fundid;
	}
	public String getFundName() {
		return fundName;
	}
	public void setFundName(String fundName) {
		this.fundName = fundName;
	}
	public String getTag() {
		return tag;
	}
	public void setTag(String tag) {
		this.tag = tag;
	}
	
	public void setMyStock(MyAccountStocks acStock) {
		stockNo = acStock.getStkCode();
		stockName = acStock.getStkName();
		myCostPrice = acStock.getCostPrice();
		myProfiteRate = acStock.getProfitRate();
		stkQty = acStock.getStkQty();
		this.backupInfo = acStock.toString();
	}

	public String curPrice(){
		return " 现价:"+getCurPrice();
	}

	public String highPrice(){
		return " 最高:"+gethPrice();
	}

	public String lowPrice(){
		return " 最低:"+getLowPrice();
	};

	public String cur2highAbsDisStr(){
		return "回落:"+ CaculateUtils.getPercentByFloat(cur2highAbsDis());
	}

	public float cur2highAbsDis() {
		return CaculateUtils.getFloatDis(getCurPrice(), gethPrice());
	}

	public String nameWithCode(){
		return stockName +"("+stockNo+") ";
	}

	public float cur2CloseDisAbsDis(){
		return CaculateUtils.getFloatDis(getCurPrice(),getlastClose());
	}

	public String cur2CloseDisAbsDisStr(){
		return " 涨跌"+CaculateUtils.getPercentByFloat(cur2CloseDisAbsDis());
	}


	public String getStkLineH5() {
		return StockUtils.getStkH5Line(stockNo);
	}

	public String getBackupInfo() {
		return backupInfo;
	}

	public void setBackupInfo(String backupInfo) {
		this.backupInfo = backupInfo;
	}
}
